package com.xyq;

import java.util.*;

//演示collections
public class CollectionsDemo {
    public static void main(String[] args) {
        test1();
    }
    public static void test0(String[] args) {
        List<String> list = new LinkedList<>();//多态只需动后面
        Collections.addAll(list,"阿伟","啊你","啊他","啊她");
        list.forEach(System.out::println);
        System.out.println("----------------");

        //打乱
        Collections.shuffle(list);
        list.forEach(System.out::println);

    }
    public static void test1(){
        List<Integer> list = new ArrayList<>();
        Collections.addAll(list,1,2,3,4,5,6,7,8,9,10);
        //按照倒序给集合排序
        Collections.sort(list);
        list.forEach(System.out::println);
        Collections.sort(list, new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o2 - o1;
            }
        });
        System.out.println("----------------");
        list.forEach(System.out::println);

        List<Student> list1 = new ArrayList<>();
        list1.add(new Student("张三", 20));
        list1.add(new Student("李四", 21));
        list1.add(new Student("王五", 22));
        list1.add(new Student("赵六", 23));

        Collections.sort(list1);//排序
        list1.forEach(System.out::println);
        List<Integer> synchronizedList = Collections.synchronizedList(list);


    }


}
